open(BUFF,"venny1.txt");
open(WRBUFF,">output_venny.txt");
$line = <BUFF>;
chomp($line);
@array1 = split("\t",$line);
print @array1."\t@array1\n";

#$line = <BUFF>;
while($line = <BUFF>)
{
	chomp($line);
	#$line =~ s/\s+/\t/g;
	#$line =~ s/\t+/\t/g;
	@array = split("\t",$line);
	if(@array > @array1)
	{
		print "nonsense\n";
	}
	#print @array."\n";
	for($i=0;$i<@array;$i++)
	{
		chomp($array[$i]);
		if($array[$i] ne "---" && $array[$i] ne "")
		{
			@arr = ();
			$delimit = '///';
			#print $array[$i]."\n";
			if($array[$i] =~ m/$delimit/)
			{
				#print $array[$i]."\n";
				@arr = split($delimit,$array[$i]);
				###print "@arr\n";	
				
			}
			else
			{
				$arr[0] = $array[$i];
			}
			#print "\t".@arr;
			for($y=0;$y<@arr;$y++)
			{
				$arr[$y] =uc($arr[$y]);
				if(exists($hash{$arr[$y]}))
				{
					if(!($hash{$arr[$y]} =~ m/$array1[$i]/))
					{
						$hash{$arr[$y]} = $hash{$arr[$y]}.",".$array1[$i];
					}
				}
				else
				{
					$hash{$arr[$y]} = ",".$array1[$i];
				}
			
			}
		}
	}
	#print "\n";
}
foreach $key (sort keys %hash)
{
  print WRBUFF "$key\t$hash{$key}\n";
}

